import {validateip, validateChinese, validatenull} from '@/util/validate'
//验证ip地址
const validateIp = (rule, value, callback) => {
  if (validateip(value)[0]) {
    callback(new Error(validateip(value)[1]))
  } else {
    callback()
  }
}
//验证端口
const validatePort = (rule, value, callback) => {

  if (validatenull(value)) {
    callback(new Error("端口不能为空"))
  } else if (!(parseInt(value) >= 0 && parseInt(value) <= 65535)) {
    callback(new Error("端口范围0~65535"))
  } else {
    callback()
  }
}
//验证服务名
const validateServerName = (rule, value, callback) => {
  if (!validateChinese(value)) {
    callback(new Error("不能包含中文"))
  } else {
    callback()
  }
}
export const tableOption = {
  addBtn: false,
  addTitle: '新增节点',
  border: true,
  index: true,
  indexLabel: "序号",
  stripe: true,
  menuAlign: "center",
  align: "center",
  searchMenuSpan: 6,
  column: [
    {
      type: "input",
      label: "IP地址",
      prop: "serverIp",
      search: true,
      maxlength: 20,
      showWordLimit: true,
      rules: [{
        required: true,
        trigger: 'blur',
        validator: validateIp
      }],
    },
    {
      type: 'input',
      label: "端口",
      prop: "serverPort",
      search: true,
      maxlength: 5,
      showWordLimit: true,
      rules: [{
        required: true,
        trigger: 'blur',
        validator: validatePort
      }],
    },
    {
      type: "input",
      label: "服务名",
      prop: "springApplicationName",
      search: true,
      maxlength: 30,
      showWordLimit: true,
      rules: [{
        required: true,
        trigger: 'blur',
        validator: validateServerName,

      }],
    },
    {
      width: 170,
      type: "input",
      label: "创建时间",
      prop: "createTime",
      addDisplay: false,
      editDisplay: false,
    },
    {
      span:24,
      type: "textarea",
      label: "备注",
      prop: "remark",
      maxlength: 100,
      showWordLimit: true,
    }]
}

export const tableFrontGrayOption = {
  addBtn: false,
  editBtn: false,
  delBtn: false,
  border: true,
  index: true,
  indexLabel: "序号",
  stripe: true,
  menuAlign: "center",
  align: "center",
  searchMenuSpan: 6,
  column: [
    {
      type: "input",
      label: "前端唯一标识",
      prop: "frontSign"
    },
    {
      type: "input",
      label: "部门",
      prop: "deptId",
      slot: true,
      overHidden: true
    },
    {
      type: "input",
      label: "角色",
      prop: "role",
      slot: true,
      overHidden: true,

    },
    {
      type: "input",
      label: "创建时间",
      prop: "createTime"
    },
  ]
}